package yanivosher.aiproject;

import java.util.ArrayList;

public abstract class Agent {

	public int id = 0;
	public int stepsCost = 0;
	public int chemsDestroyed = 0;
	
	public Vertex currentVertex;
	public Vertex destinationVertex;
	public ArrayList<Step> stepListForPrint;
	public Agent opponent;

	public Agent(Vertex currentVertex, Vertex destinationVertex, int id) {
		this.currentVertex = currentVertex;
		this.destinationVertex = destinationVertex;
		this.stepListForPrint = new ArrayList<Step>();
		this.id = id;
	}
	
	public Agent(Agent agent) {
		this.currentVertex = new Vertex(agent.currentVertex);
		this.destinationVertex = new Vertex(agent.destinationVertex);
		this.stepListForPrint = new ArrayList<Step>();
		this.chemsDestroyed = agent.chemsDestroyed;
		this.stepsCost = agent.stepsCost;
		this.id = agent.id;
	}

	public abstract boolean idDone();
	
	public abstract Agent deepCopy();

	public abstract Step makeAmove(Graph curr);
	
	public void raiseScore(int cost) {
		stepsCost += cost;
	}

	protected ArrayList<Vertex> getAvailableEdges()
	{
		ArrayList<Vertex> retList = new ArrayList<Vertex>();
		for (Edge edge : Environment.getInstance().graph.getEdges()) {
			if(edge.getSource().equals(this.currentVertex))
				retList.add(edge.getDestination());
			if(edge.getDestination().equals(this.currentVertex))
				retList.add(edge.getSource());
		}
		return retList;
	}
	
	public Agent getOpponent()
	{
		if (opponent == null) {
			for (Agent agent : Environment.getInstance().agents) {
				if (this.id != agent.id) {
					return agent;
				}
			}
			return null;
		}
		else {
			return opponent;
		}
	}
	
	public int getScore() {
		return this.chemsDestroyed*Environment.chemDestroyedReward - this.stepsCost;
	}
}
